package com.example.demo.model;

import com.example.demo.constant.Constant;
import lombok.Data;

@Data
public class Result {
    private  int code;
    private  String msg;
    private Object data;

    /**
     * 业务执⾏成功时返回的⽅法
     * @param data
     * @return
     */
    public static Result success(Object data){
        Result result = new Result();
        result.setCode(Constant.RESULT_CODE_SUCCESS);
        result.setMsg("");
        result.setData(data);
        return result;
    }
    /**
     * 业务执⾏失败时返回的⽅法
     * @return
     */
    public static Result fail(String msg){
        Result result = new Result();
        result.setCode(Constant.RESULT_CODE_FAIL);
        result.setMsg(msg);
        result.setData("");
        return result;
    }

    /**
     * 用户未登录时返回的方法
     * @param code
     * @param msg
     * @param data
     * @return
     */

    public static Result unlogin(int code , String msg, Object data){
        Result result = new Result();
        result.setCode(Constant.RESULT_CODE_UNLOGIN);
        result.setMsg("用户未登录");
        result.setData(data);
        return result;
    }

}
